package org.gvp.record.repository.impl;

import lombok.RequiredArgsConstructor;

import org.springframework.stereotype.Repository;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.gvp.record.repository.ReportDetailRepository;
import org.gvp.record.mapper.ReportDetailMapper;
import org.gvp.record.pojo.ReportDetail;
import java.util.List;
/**
 * 报销单详细信息表 数据层接口实现类
 */
@Repository
@RequiredArgsConstructor
public class ReportDetailRepositoryImpl implements ReportDetailRepository {
    private final ReportDetailMapper reportDetailMapper;

    @Override
    public int append(ReportDetail pojo) {
        return this.reportDetailMapper.insert(pojo);
    }

    @Override
    public int modify(ReportDetail pojo) {
        return this.reportDetailMapper.updateById(pojo);
    }

    @Override
    public int cancel(Integer id) {
        return this.reportDetailMapper.deleteById(id);
    }

    @Override
    public ReportDetail searchById(Integer id) {
        return this.reportDetailMapper.selectById(id);
    }

    @Override
    public List<ReportDetail> searchList() {
        return this.reportDetailMapper.selectList(null);
    }

    @Override
    public Long searchCount(String field) {
        return this.reportDetailMapper.selectCount(null);
    }

    @Override
    public List<ReportDetail> searchLimit(int start, int end) {
        return this.reportDetailMapper.selectList(Wrappers.<ReportDetail>lambdaQuery()
                .last("LIMIT %d,%d".formatted(start,end))
                .orderByDesc(ReportDetail::getOrder)
                .orderByAsc(ReportDetail::getId)
        );
    }

    @Override
    public List<ReportDetail> searchListByReportId(Integer reportId, int start, int end) {
        return this.reportDetailMapper.selectList(Wrappers.<ReportDetail>lambdaQuery()
                        .eq(ReportDetail::getReportId,reportId)
                .last("LIMIT %d,%d".formatted(start,end))
                .orderByDesc(ReportDetail::getOrder)
                .orderByAsc(ReportDetail::getId)
        );
    }

    @Override
    public List<ReportDetail> searchListByReportId(Integer reportId) {
        return this.reportDetailMapper.selectList(Wrappers.<ReportDetail>lambdaQuery()
                .eq(ReportDetail::getReportId,reportId)
                .orderByDesc(ReportDetail::getConsumeDate)
                .orderByDesc(ReportDetail::getId)
        );
    }
}
